var adduser = {
	
	id:0,
	account:'',
		
	initPage:function(){
		adduser.initLoad(adduser.id);
		$("#cancelBtn").click(function(){
			adduser.backList();
		});
		$("#confirmBtn").click(function(){
			adduser.saveOrupdate();
		});
		$("#addOrUpdateUser").html(language.addOrUpdateUser[mainIndex.languageType]);
		$("#user_account").html(language.user_account[mainIndex.languageType]);
		$("#loginPassword").html(language.loginPassword[mainIndex.languageType]);
		$("#remarkInformation").html(language.remarkInformation[mainIndex.languageType]);
		$("#confirmBtn").html(language.confirmBtn[mainIndex.languageType]);
		$("#cancelBtn").html(language.cancelBtn[mainIndex.languageType]);
		$("#account").attr('placeholder',language.user_account[mainIndex.languageType]+"...");
		$("#password").attr('placeholder',language.loginPassword[mainIndex.languageType]+"...");
		$("#remark").attr('placeholder',language.remarkInformation[mainIndex.languageType]+"...");
	},
	
	initLoad : function(id) {
		if(id && id!=0){
			usermanager.getUser({"userId":id},function(data){
				if(data.data && data.retCode == 0){
					var obj= data.data;
					adduser.account =  obj.account;
					$("#account").val(obj.account);
					$("#password").val(obj.password);
					$("#remark").val(obj.remark);
				}
			});
		}
	},
	
	saveOrupdate:function(){
		var account = $("#account").val();
		var password = $("#password").val();
		var remark = $("#remark").val();
		if( account=='' || password=='' ){
			util.alertMessage(language.emptyParams[mainIndex.languageType]);
		}else{
			var params ={
					'account':account,
					'password':password,
					'userType':"2",
					'remark':remark,
			};
			if(adduser.id){
				params['userId'] = adduser.id;
				if(params['account'] == adduser.account){
					params['account'] = '';
				}
			}
			usermanager.addOrUpdateUser(params,adduser.add_successcb,adduser.add_successcb);
		}
	},
	
	add_successcb:function(data){
		 if(data.retCode == 0){
			 layer.msg(language.operatorSuccess[mainIndex.languageType], {icon: 1});
			 adduser.backList();
		 }else if(data.retCode == -1){
			 util.alertMessage(language.existAccount[mainIndex.languageType]);
		 }
	},
		
	backList:function(){
		util.loadContent(util.webpath+'user/backUserList.html','contentDiv',{},function(){});
	},
}
